﻿<link rel="stylesheet" type="text/css" href="{config.webpath}scripts/artdialog/ui-dialog.css" />
<script type="text/javascript" charset="utf-8" src="{config.webpath}scripts/artdialog/dialog-plus-min.js"></script>
<script type="text/javascript">
  $(function(){
   bindFavorite('add', '{site.build_path}', '{channel}', '{model.id}');
  });

  //绑定按钮事件
  function bindFavorite(action, site, channel, id) {
   $('#myFavorite').bind('click', function () {
    favoriteAdd(action, site, channel, id);
   });
  }

  //提交收藏AJAX处理
  function favoriteAdd(action, site, channel, id) {
   //提交操作
   $.ajax({
    type: 'GET',
    dataType: 'json',
    url: '/plugins/favorite/ajax.ashx',
    data: { "action": action, "site": site, "channel": channel, "id": id },
    timeout: 20000,
    success: function (data, textStatus) {
     if (data.status == 1) {
      $("#myFavorite").text("已收藏");
      $('#myFavorite').unbind("click"); //移除绑定事件
      var d = dialog({ content: data.msg }).show();
      setTimeout(function () {
       d.close().remove();
      }, 2000);
     } else {
      dialog({ title: '提示', content: data.msg, okValue: '确定', ok: function () { } }).showModal();
     }

    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
     dialog({ title: '提示', content: "状态：" + textStatus + "；出错提示：" + errorThrown, okValue: '确定', ok: function () { } }).showModal();
    }
   });
   return false;
  }
</script>
    
<div class="favorite-box">
  <a id="myFavorite"><script type="text/javascript" src="{config.webpath}plugins/favorite/ajax.ashx?id={model.id}"></script></a>
</div>
<style type="text/css">
.favorite-box{padding:20px 0 30px;text-align:center;}
.favorite-box a{padding:10px;border-radius:8px;background:#169b27;color:#fff;cursor:pointer;}
</style>
